package cn.yujiago.shiro.controller;

import cn.yujiago.shiro.domain.MenuDO;
import cn.yujiago.shiro.pojo.AuthNode;
import cn.yujiago.shiro.pojo.LayuiResult;
import cn.yujiago.shiro.pojo.LayuiTableResult;
import cn.yujiago.shiro.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping("/menu/list")
    @ResponseBody
    public LayuiTableResult<MenuDO> getMenusByCondition(@RequestParam("page") int page, @RequestParam("limit") int limit){
        return menuService.getMenusByCondition(page, limit);
    }

    @RequestMapping("/menu/authTree")
    @ResponseBody
    public LayuiTableResult<AuthNode> getAuthTree(@RequestParam("userId") Long userId){
        return menuService.getAuthTreeByUserId(userId);
    }

    @RequestMapping("/menu/authTreeByRoleId")
    @ResponseBody
    public LayuiTableResult<AuthNode> getAuthTreeByRoleId(@RequestParam("roleId") Long roleId){
        return menuService.getAuthTreeByRoleId(roleId);
    }

    @RequestMapping("/menu/updateRoleMenu")
    @ResponseBody
    public LayuiResult updateRoleMenu(@RequestParam("roleId") Long roleId, @RequestParam(value = "menuIds[]", required = false) List<Long> menuIds){

        return menuService.updateRoleMenu(roleId, menuIds);
    }
}
